Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create EscapedFrameIntervalsFinder and ComplexStackVariableTransformer #1157

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

ptomin
Copy link
Collaborator

@ptomin ptomin commented Feb 16, 2022

There are two phases. EscapedFrameIntervalsFinder finds intervals in the
[[-12, -4], (struct ""str"" 0008 (0 int32 dw0000) (4 real32 r0004))]
form. Then ComplexStackVariableTransformer rewrites expressions like
fp - <offset> if offset is inside of one of the intervals collected by
EscapedFrameIntervalsFinder.
Current implementation works only if user or environment procedure
signature is defined.

`EscapedFrameIntervalsFinder` finds intervals in the
`[[-12, -4], (struct ""str"" 0008 (0 int32 dw0000) (4 real32 r0004))]`
form.  Then `ComplexStackVariableTransformer` rewrites expressions like
`fp - <offset>` if offset is inside of one of  the intervals collected by
`EscapedFrameIntervalsFinder`.
Current implementation works only if user or environment procedure
signature is defined.
@ptomin ptomin self-assigned this Feb 16, 2022
@ptomin ptomin added enhancement This is a feature request local-stack-variables This issue is about incorrect propagation/elimination of local stack variables labels Feb 16, 2022
@ptomin ptomin requested a review from uxmal February 16, 2022 18:24
Copy link
Owner

@uxmal uxmal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions regarding the output. Code looks fine.

@@ -7,7 +7,7 @@
// 10001000: Register (ptr32 Eq_n) sum_wrapper(Stack (ptr32 Eq_n) ptrArg04, Stack (ptr32 Eq_n) ptrArg08)
PyObject * sum_wrapper(PyObject * ptrArg04, PyObject * ptrArg08)
{
PyObject * eax_n = PyArg_ParseTuple(ptrArg08, "ii:sum", fp - 0x04, fp - 0x08);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed earlier, the declarations of the two new variables can be done in a future commit.

QueryPerformanceCounter(fp - 0x14);
ui32 esi_n = esi_n ^ (dwLoc10 ^ dwLoc14);
QueryPerformanceCounter(&tLoc14);
ui32 esi_n = esi_n ^ (tLoc14.dw0004 ^ tLoc14);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here? tLoc14 seems to have sub-structure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of tLoc14 is LARGE_INTEGER union.

typedef union _LARGE_INTEGER {
  struct {
    DWORD LowPart;
    LONG  HighPart;
  } DUMMYSTRUCTNAME;
  struct {
    DWORD LowPart;
    LONG  HighPart;
  } u;
  LONGLONG QuadPart;
} LARGE_INTEGER;

The result should be

ui32 esi_n = esi_n ^ (tLoc14.HighPart ^ tLoc14.LowPart);

It looks like later phase (TypeAnalysis/ComplexExpressionRewiter) can't transform correctly accesses to such unions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make an issue to track this then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1159

@uxmal uxmal merged commit 28448ba into uxmal:master Feb 21, 2022
@ptomin ptomin deleted the complex-stack-variable-transformer branch February 21, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is a feature request local-stack-variables This issue is about incorrect propagation/elimination of local stack variables
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants